/**
 *CreateChessBoard.java
 */

package GUI;

import chess.MouseHandeling;
import gameStructure.*;
import java.awt.*;
import java.util.ArrayList;
import javax.swing.*;
 
public class CreateChessBoard extends JLabel{
    public SquareOnBoard[][] sqrs;
    
    /** Creates a new instance of CreateChessBoard */
    public CreateChessBoard(){
        setSize(800,700);
        setLayout(new GridLayout(8,8));
        sqrs = new SquareOnBoard[8][8];
        createSquares();
    }
    
    public CreateChessBoard(int h, int w){
        setSize(h,w);
        setLayout(new GridLayout(8,8));
        sqrs = new SquareOnBoard[8][8];
        createSquares();
    }
    
    private void createSquares(){
        for(int i=0;i<8;i++){
            for(int j=0;j<8;j++){
                SquareOnBoard panel = new SquareOnBoard(""+i+""+j);
                panel.setSquareColor(getColor(i,j));
                panel.addMouseListener(new MouseHandeling());
                add(panel);
                sqrs[i][j] = panel;
            }
        }
    }
    
    private Color getColor(int x, int y){
        if((x+y)%2 == 0)
            return Color.WHITE;
        else
            return Color.DARK_GRAY;
    }
    
    /**
     * TODO : apo tin proigoumeni Piece, tha kratithoun: addPiece kai removePiece 
     * oste na topothetounde i ikones sta andistiha simia se andistihia me tin Board. 
     * @param Board O pinakas me oles ta Pieces kai tis thesis stis opies auta vriskonde
     * @return 
     */
    public CreateChessBoard setPieces( ArrayList Board){
        CreateChessBoard t = new CreateChessBoard();
        
        Point pos= new Point();
        pos.x=0;
        pos.y=1;
        boolean mov = false;
        sqrs[pos.x][pos.y].addPiece(new paintPiece( mov, pos,'w', "Knight"));
        sqrGUI p3 = new paintPiece(!mov, pos, 'b', "Knight");
        p3.addMouseListener(new MouseHandeling());
        sqrs[7][1].addPiece(p3);
        
        return t;
    }
}